<?php
/*
* Copyright (c) 2010 by Cediti
*
* You may distribute under the terms of either the GNU Lesser General
* Public License or the new BSD License, as specified in the README file.
*/
// created :	09/02/2010
// version :	02/04/2010

abstract class Cmis_Services_Abstract implements Cmis_Services_Interface
{
	/**
	 * @var Cmis_Client_Services_Interface
	 */
	protected $_services;

	public function __construct(Cmis_Client_Services_Interface $services)
	{
		$this->_services = $services;
		$this->_init();
	}

	/**
	 * Name are taked from the class name (after '_Services_')
	 * @see Cmis_Services_Interface#getServiceName()
	 */
	public function getServiceName()
	{
		$name = get_class($this);
		return substr($name, strpos($name, '_Services_') + 10);
	}

	public function getServices()
	{
		return $this->_services;
	}

    /**
     * Check if the type of hte link is corresponding
     * @param array $link
     * @param string $type
     * @return bool
     */
    protected function _checkTypeLink($link, $type)
    {
        return ($link['type'] == $type);
    }

    /**
     * Call in the constructor to init some parameters or configuration in the
     * child class
     * @return void
     */
    protected function _init()
    {}

	/**
	 * @param Cmis_Repository_Id $repositoryId
	 * @return Cmis_Repository_Info
	 */
	protected function _getRepositoryInfo(Cmis_Repository_Id $repositoryId)
	{
		return $this->getServices()->getService('Repository')->getRepositoryInfo($repositoryId);
	}
}

# EOF
